<template>
  <div class="productInfo">
    <div>
      <el-page-header class="head" @back="goBack" :content="content">
      </el-page-header>
    </div>
    <div>
      <el-form label-width="80px" class="input">

        <el-form-item label="品牌名称">
          <el-input v-model="name"></el-input>
        </el-form-item>

        <el-button @click="creatBrand" class="button">立即创建</el-button>
      </el-form>

    </div>

  </div>
</template>
<script>
  export default {
    data() {
      return {
       name:'',
       content:'新增品牌页面'
      }
    },
    async created() {
      let id=this.$route.params.id;
     
      if(id){
        let res= await this.$http.get('brand/get?id='+id);
        console.log(res);
        this.content='编辑品牌页面';
        this.name=res.data.name;
      }else{
        this.content='新增品牌页面'
      }

    },
    methods: {
     
      goBack() {
        javascript: history.back(-1);
      },
      async creatBrand() {
        if(this.$route.params.id){
          let res= await this.$http.post('brand/update',{
          name:this.name,
          id:this.$route.params.id,
         })
        }else{
          let res= await this.$http.post('brand/insert',{
          name:this.name
         })
        console.log(res)
        }
        
        this.$router.push('/brand/list')
      },

    },
  }
</script>
<style>
   .head {
    margin: 20px;
  }
.input{
  margin: 0 10px;
}
   .button {
    background: #008080;
    color: white;
    margin-left: 80px;
  }

  
</style>